﻿#region Imports
using System;
using System.Collections.ObjectModel;
using System.Linq;
using CommonUtilities.Enums;
using CommonUtilities.Exceptions;
using CommonUtilities.Extensions;
using CommonUtilities.Messages;
using CommonUtilities.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endregion

namespace CommonUtilities.UnitTest.UTExtensions
{
    [TestClass]
    public class EnumExtensions_Test
    {
        #region Declarations
        eButtonDirection btnDirectn = eButtonDirection.Default;
        #endregion

        #region Test methods
        [TestMethod]
        public void GetValues_Test()
        {
            ObservableCollection<eButtonDirection> expected = new ObservableCollection<eButtonDirection>();
            expected.Add(eButtonDirection.Default);
            expected.Add(eButtonDirection.Top);
            expected.Add(eButtonDirection.Bottom);
            expected.Add(eButtonDirection.Left);
            expected.Add(eButtonDirection.Right);

            ObservableCollection<eButtonDirection> actual = new ObservableCollection<eButtonDirection>();
            actual = btnDirectn._GetValues().ToObservableCollection();

            if (expected.GetCount() != actual.GetCount()) throw new UnitTestFailedException();
            for (int i = 0; i < expected.GetCount(); i++)
            {
                Assert.AreEqual(expected.OrderByDirection(val => val.ToString()).ElementAt(i),
                    actual.OrderByDirection(val => val.ToString()).ElementAt(i),
                    UnitTestFailedException.Description);
            }
        }

        [TestMethod]
        public void TryParse_Test()
        {
            eButtonDirection expected = eButtonDirection.Bottom;
            string sButtonDirection = expected.ToString();

            eButtonDirection actual;
            if (btnDirectn._TryParse(sButtonDirection, out actual))
                Assert.AreEqual(expected, actual, UnitTestFailedException.Description);
            else throw new UnitTestFailedException();

            //buttonDirection._TryParse(sButtonDirection, out eButtonDirection);
        }

        [TestMethod]
        public void ForEach_Test()
        {
            ObservableCollection<eButtonDirection> expected = new ObservableCollection<eButtonDirection>();
            expected.Add(eButtonDirection.Default);
            expected.Add(eButtonDirection.Top);
            expected.Add(eButtonDirection.Bottom);
            expected.Add(eButtonDirection.Left);
            expected.Add(eButtonDirection.Right);

            ObservableCollection<eButtonDirection> actual = new ObservableCollection<eButtonDirection>();
            btnDirectn._ForEachEnum(val => actual.Add(val), null);

            if (expected.GetCount() != actual.GetCount()) throw new UnitTestFailedException();
            for (int i = 0; i < expected.GetCount(); i++)
            {
                Assert.AreEqual(expected.OrderByDirection(val => val.ToString()).ElementAt(i),
                    actual.OrderByDirection(val => val.ToString()).ElementAt(i),
                    UnitTestFailedException.Description);
            }
        }

        public void Convert_Test()
        {

        }

        public void ConvertByName_Test()
        {

        }

        public void ConvertByValue_Test()
        {

        }

        [TestMethod]
        public void Contains_Test()
        {
            eButtonDirection e1 = eButtonDirection.Default | eButtonDirection.Top;
            eButtonDirection e2 = eButtonDirection.Default | eButtonDirection.Bottom;

            Assert.IsFalse(e1.Contains(eButtonDirection.Bottom), UnitTestFailedException.Description);
            Assert.IsTrue(e2.Contains(eButtonDirection.Bottom), UnitTestFailedException.Description);
        }

        public void HasFlag_Test()
        {

        }
        #endregion
    }
}
